package com.coda.clouddisk.controller.impl;

import com.coda.clouddisk.annotation.Loggable;
import com.coda.clouddisk.controller.SuperController;
import com.coda.clouddisk.controller.inter.FileCategoryController;
import com.coda.clouddisk.entity.FileShareRecord;
import com.coda.clouddisk.entity.KeSunAttachment;
import com.coda.clouddisk.entity.KesunReturn;
import com.coda.clouddisk.message.MessageContext;
import com.coda.clouddisk.service.impl.FileShareRecordServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


import java.util.List;
import java.util.Map;

@RestController()
@RequestMapping("/clouddisk/fileShare")
public class FileShareRecordControllerImpl extends SuperController implements FileCategoryController {
    @Autowired
    private FileShareRecordServiceImpl fileShareRecordService;
    @Override
    public Map<String, Object> convertData(Map<String, Object> data) {
        setSuperService(fileShareRecordService);
        return data;
    }

    /**
     * 创建文件分享
     */
    @PostMapping("/shareFile")
    @Loggable("创建文件分享")
    public KesunReturn createFileShare(@RequestBody FileShareRecord fileShareRecord){
        fileShareRecordService.createFileShare(fileShareRecord);
        KesunReturn kesunReturn = new KesunReturn();
        kesunReturn.setMsg("分享成功");
        kesunReturn.setCode(MessageContext.SUCCESS_CODE);
        return kesunReturn;
    }

    /**
     * 查看分享的文件
     */
    @GetMapping("/getShareFile")
    @Loggable("获取分享的文件")
    public KesunReturn getShareFile(@RequestParam Map<String,Object> data){
        List<FileShareRecord> FileShareRecord = fileShareRecordService.getShareFile(data);
        KesunReturn kesunReturn = new KesunReturn();
        if (FileShareRecord == null || FileShareRecord.size() == 0){
            kesunReturn.setMsg("未找到文件");
            kesunReturn.setCode(MessageContext.ERROR_CODE);
        }else{
            kesunReturn.setMsg("获取成功");
            kesunReturn.setObj(FileShareRecord);
            kesunReturn.setCode(MessageContext.SUCCESS_CODE);
        }
        return kesunReturn;
    }

    /**
     * 查看分享出去的文件
     */
    @GetMapping("/getShareFileOut")
    @Loggable("查看分享出去的文件")
    public KesunReturn getShareFileOut(@RequestParam Map<String,Object> data){
        List<FileShareRecord> FileShareRecord = fileShareRecordService.getshareFileOut(data);
        KesunReturn kesunReturn = new KesunReturn();
        if (FileShareRecord == null || FileShareRecord.size() == 0){
            kesunReturn.setMsg("没有分享出去的文件");
        }
        kesunReturn.setObj(FileShareRecord);
        return kesunReturn;
    }
}
